<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    let data = [
        {
            "terminalId": 1690001414,
            "terminalType": "4",
            "ciId": 1,
            "ciStatus": 3
        },
        {
            "terminalId": 1690001414,
            "terminalType": "4",
            "ciId": 2,
            "ciStatus": 2
        },
        {
            "terminalId": 1690001414,
            "terminalType": "4",
            "ciId": 3,
            "ciStatus": 0
        },
        {
            "terminalId": 1690001414,
            "terminalType": "4",
            "ciId": 4,
            "ciStatus": 3
        },
        {
            "terminalId": 1690001414,
            "terminalType": "4",
            "ciId": 5,
            "ciStatus": 1
        },
        {
            "terminalId": 2010130070,
            "terminalType": "3",
            "ciId": 1,
            "ciStatus": 3
        },
        {
            "terminalId": 2010130070,
            "terminalType": "3",
            "ciId": 2,
            "ciStatus": 1
        },
        {
            "terminalId": 2010130070,
            "terminalType": "3",
            "ciId": 3,
            "ciStatus": 3
        }
    ]


    // 对data数组按terminalId进行分组


    let group = data.reduce((acc, cur) => {
        acc[cur.terminalId] = acc[cur.terminalId] || []
        acc[cur.terminalId].push(cur)
        return acc
    }, {})
    console.log(group)


    const arr = [
        {date: '2020-10-13',rank : 1 },
        {date: '2020-10-13'},
        {date: '2020-10-08'},
        {date: '2020-10-05'},
        {date: '2020-10-05'}
    ];

    // 根据日期进行排序
    arr.sort((a, b) => a.date.localeCompare(b.date));

    let rank = 1;

    arr[0].rank = 1

    for (let i = 1; i < arr.length - 1; i++) {
        const prev = arr[i-1]
        const item = arr[i]
        const next = arr[i + 1]

        if(prev.date === item.date ){
            item.rank = rank
        }else {
            item.rank = ++rank
        }
    }

    arr[arr.length - 1].rank = rank


    console.log(arr);


</script>
</body>
</html>
